<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class VendorVerifiy extends Model
{

    protected $table = 'ims_hhm_vendor_verifiy';

    protected $fillable = [
        'outbound_id',
        'user_id',
        'vendor_id',
        'store_id',
        'created_at',
        'updated_at'
    ];

    protected $casts = [
        'created_at' => 'datetime',
        'updated_at' => 'datetime'
    ];

    /**
     * 关联发货单
     */
    public function outbound()
    {
        return $this->belongsTo(OrderOutbound::class, 'outbound_id', 'id');
    }

    /**
     * 关联用户
     */
    public function user()
    {
        return $this->belongsTo(Member::class, 'user_id', 'uid');
    }

    /**
     * 关联供应商
     */
    public function vendor()
    {
        return $this->belongsTo(Vendor::class, 'vendor_id', 'id');
    }

    /**
     * 关联门店
     */
    public function store()
    {
        return $this->belongsTo(Store::class, 'store_id', 'id');
    }

    /**
     * 查询指定门店的核销记录
     */
    public function scopeByStore($query, $storeId)
    {
        return $query->where('store_id', $storeId);
    }

    /**
     * 查询指定用户的核销记录
     */
    public function scopeByUser($query, $userId)
    {
        return $query->where('user_id', $userId);
    }

    /**
     * 查询指定发货单的核销记录
     */
    public function scopeByOutbound($query, $outboundId)
    {
        return $query->where('outbound_id', $outboundId);
    }

    /**
     * 查询指定供应商的核销记录
     */
    public function scopeByVendor($query, $vendorId)
    {
        return $query->where('vendor_id', $vendorId);
    }
}
